//
// Created by Administrator on 2015/9/17 0017.
//

#include "common.h"
#include <jni.h>
/**
 *
 * str class_name
 *
 */
/*void throwException(int errorCode, JNIEnv *env, const char *className) {
//nullchecks just to prevent segfaults,
   *//* if ((*env)->ExceptionCheck(env) == JNI_TRUE) {
        return;
    }
    jclass exClass = (*env)->FindClass(env, className);
    if (exClass == NULL)
        return;
    //调用构造方法
    jmethodID mid = (*env)->GetMethodID(env, exClass, "<init>", "(I)V");
    if (mid == NULL)
        return;
    //调用构造方法初始化对象
    jobject exception = (*env)->NewObject(env, exClass, mid, errorCode);
    if (exception != NULL)
        (*env)->Throw(env, exception);
    (*env)->DeleteLocalRef(env, exception);
    //释放内存
    (*env)->ReleaseStringChars(env, NULL, className);*//*
}*/
jstring CharTojstring(JNIEnv* env, const char* str)
{
    jstring test = NULL;
    jsize   len   =   strlen(str);
    jclass   clsstring   =   (*env)->FindClass(env, "java/lang/String");
    jstring   strencode   =   (*env)->NewStringUTF(env,"UTF-8");
    jmethodID   mid   =   (*env)->GetMethodID(env,clsstring,   "<init>",   "([BLjava/lang/String;)V");
    jbyteArray   barr   =   (*env)-> NewByteArray(env,len);
    (*env)-> SetByteArrayRegion(env,barr,0,len,(jbyte*)str);
    return (jstring)(*env)-> NewObject(env,clsstring,mid,barr,strencode);
   // return  test;
}